package com.atguigu.day06;

public class Test05 {
    public static void main(String[] args) {

        Employee[] p1 = new Employee[]{
                new Employee(),
                new Employee(),
                new Employee(),
                new Employee()};

        p1[0].setInfo(0, "老王", 0, 35);
        p1[1].setInfo(1, "老李", 0, 36);
        p1[2].setInfo(2, "老周", 0, 31);
        p1[3].setInfo(3, "老张", 0, 33);

        /*p1[0].id = 0;
        p1[0].name="老王";
        p1[0].salary = 0;
        p1[0].age = 35;*/
/*
        p1[0].setInfo(0,"老王",0,35);
        p1[1].setInfo(1,"老李",0,36);
        p1[2].setInfo(2,"老周",0,31);
        p1[3].setInfo(3,"老张",0,33);
*/
        EmployeeManager em1 = new EmployeeManager();
        for (int i = 0; i < p1.length; i++) {
            p1[i].printInfo();
        }
        em1.sort(p1);
        for (int i = 0; i < p1.length; i++) {
            p1[i].printInfo();
        }
        em1.addSalary(p1, 1000);
        for (int i = 0; i < p1.length; i++) {
            p1[i].printInfo();
        }
    }
}

class Employee {
    int id = 0;
    String name = "";
    double salary = 0;
    int age = 0;

    void printInfo() {
        System.out.println("id" + this.id + "  姓名" + this.name + "  工资" + this.salary + "  年龄" + this.age);
    }

    void setInfo(int i, String n, double s, int a) {
        this.id = i;
        this.name = n;
        this.salary = s;
        this.age = a;
    }
}

class EmployeeManager {
    public void print(Employee[] all) {
        for (int i = 0; i < all.length; i++) {
            all[i].printInfo();
        }
    }

    public void sort(Employee[] all) {
        for (int i = 0; i < all.length; i++) {
            for (int j = 0; j < all.length - 1 - i; j++) {
                if (all[j].age > all[j + 1].age) {
                    Employee temp = new Employee();
                    temp = all[j + 1];
                    all[j + 1] = all[j];
                    all[j] = temp;
                }
            }
        }
    }

    public void addSalary(Employee[] all, double increament) {
        for (int i = 0; i < all.length; i++) {
            all[i].salary += increament;
        }
    }
}
